package dsx.netServer;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import dsx.console.DsxConsole;
import dsx.inf.IDataTransfer;
import dsx.inf.ISlicer;
import dsx.log.ServLog;

class TCPChannelInitializer extends ChannelInitializer<SocketChannel> {

	IDataTransfer dataTransfer = null;
	ISlicer slicer = null;
	_TCPConfig config = null;
	TCPChannelTable channelTable = null;

	public TCPChannelInitializer(IDataTransfer dataTransfer, ISlicer slicer,
			_TCPConfig config, TCPChannelTable channelTable) {
		this.dataTransfer = dataTransfer;
		this.slicer = slicer;
		this.config = config;
		this.channelTable = channelTable;
	}

	@Override
	protected void initChannel(SocketChannel ch) {
		try {
			ch.pipeline().addLast(
					new TCPChannelHandler(this.dataTransfer, this.slicer,
							this.config, this.channelTable));
		} catch (Exception ex) {
			DsxConsole.out(ex.getMessage(), "net server channel init", ServLog.error);
			ch.close();
		}
	}

}
